Skip to content

Delete non-approved revisions on user deletion #6567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025

Conversation

akatsoulas
Copy link
Collaborator

  • Delete docs without revisions on user deletion

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements logic to delete documents without approved revisions during user deletion and reassign all remaining revisions to SUMO_BOT.

  • Updates the user deletion handler to conditionally delete documents if they lack an approved revision and remove non‐approved revisions otherwise.
  • Adds a new test case in the wiki tests to cover the behavior for non‐approved revision handling on user deletion.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
kitsune/wiki/tests/test_handlers.py Added a test case to verify the deletion of documents without approved revisions and proper handling of non-approved revisions.
kitsune/wiki/handlers.py Updated the on_user_deletion handler to delete documents with no approved revisions and delete or reassign non-approved revisions accordingly.

for revision in non_approved_revisions:
document = revision.document
# If current_revision is None, the document has no approved revisions
if document.current_revision is None:
Copy link
Preview

Copilot AI Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a document has multiple non-approved revisions, the loop may attempt to delete the same document multiple times, which could potentially lead to errors or unexpected behavior. Consider grouping non-approved revisions by document to ensure each document is processed only once.

Copilot uses AI. Check for mistakes.

@@ -19,5 +19,15 @@ def on_user_deletion(self, user: User) -> None:
document.contributors.add(*content_group.user_set.all())
document.contributors.remove(user)

non_approved_revisions = Revision.objects.filter(creator=user, is_approved=False)

for revision in non_approved_revisions:
Copy link
Contributor

@escattone escattone Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this loop be replaced with the following instead?

# First delete all of the docs that have no current revision but one or more of the users' unapproved revisions.
Document.objects.filter(current_revision__isnull=True, revisions__in=non_approved_revisions).delete()
# Next, delete all of the users' unapproved revisions that were not cascade deleted above.
non_approved_revisions.delete()

@akatsoulas
Copy link
Collaborator Author

@escattone PR updated

* Delete docs without revisions on user deletion
@escattone escattone merged commit 790a14b into mozilla:main Mar 18, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants